import * as hamcUtils from './gameUtils'

export function calculateLimbo(serverSeed: string, clientSeed: string, nonce: number) {
	const factor = 16777216
	const arrays = hamcUtils.getBytesGroups(serverSeed, clientSeed, nonce, 1, 4)
	const float = hamcUtils.calculateResult(arrays[0], factor)
	const result = Math.floor((99 * factor) / (float + 1)) / 100
	return result
}

/**
 * Limbo-赌场种子转换为字节-前端展示公开计算过程使用
 * @param {string} serverSeed - 服务端种子
 * @param {string} clientSeed - 客户端种子
 * @param {number} nonce - 随机数
 * @returns {object} - 返回字节对象
 */
export function casinoSeedToBytes(serverSeed: string, clientSeed: string, nonce: number) {
	return hamcUtils.casinoSeedToBytes(serverSeed, clientSeed, nonce, 1)
}

/**
 * 字节到数字的计算过程用到的分组 Limbo 前端公开过程 1组，每组4个字节
 * @param {string} serverSeed - 服务端种子
 * @param {string} clientSeed - 客户端种子
 * @param {number} nonce - 随机数
 * @returns {array} - 返回字节数组
 */
export function bytesToNumberGroups(serverSeed: string, clientSeed: string, nonce: number) {
	return hamcUtils.getBytesGroups(serverSeed, clientSeed, nonce, 1, 4)
}
